//
//  ZDSectionHeaderView.m
//  1012GiftTips
//
//  Created by Apple on 15/10/27.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDSectionHeaderView.h"
#import "UIView+ZUtility.h"

@interface ZDSectionHeaderView ()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation ZDSectionHeaderView

+ (instancetype)sectionHeaderView
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZDSectionHeaderView class]) owner:nil options:nil] lastObject];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.lineView.frame = CGRectMake(0, self.height-2, self.width * 0.5, 2);
}


- (IBAction)btnClick:(UIButton *)sender
{
    if (self.type == sender.tag)
    {
        return;
    }
    
    //改变按钮类型
    self.type = (int)sender.tag;
    
    //通知代理刷新数据
    if (self.reloadDataBlock)
    {
        self.reloadDataBlock();
        
        //移动红线
        [UIView animateWithDuration:0.1 animations:^{
            
            CGPoint point = self.lineView.center;
            
            point.x = sender.center.x;
            
            self.lineView.center = point;
        }];
    }
}



#pragma mark 懒加载
- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor redColor];
        [self addSubview:_lineView];
    }
    
    return _lineView;
}

@end
